 //注册表单的 手机号
  var err_msg = document.getElementById('err_msg');
 var name2 = document.getElementById('name2');
 var yz = document.getElementById('yz');
 var psd2 = document.getElementById('psd2');
var qpsd2 = document.getElementById('qpsd2');
 var send=document.getElementById('send');
function telfn() {
    if(name2.value == "") {
        err_msg.innerHTML = "*手机号不能为空";
        return false;
    }else{
        var regex = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
       if(regex.test(name2.value) == true) {
        return true;
        } else {
        err_msg.innerHTML = "*手机格式输入不正确";
        return false;
      }
    }
}
name2.onblur = telfn;


    var mobile=$('#name2').val();
   console.log(mobile);
     times=60,
     timer=null;

 $('#send').click(function(){
     var tel = $.trim($('#name2').val());
     // 计时开始

     timer = setInterval(djs,1000);
     $.post('/home/reg/code', {'mobile':tel,'_token':$('input[name=_token]').val()},function(num){
         if (num) {
          var regex = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
          if(regex.test(name2.value) == true){
             document.getElementById('err_msg').innerHTML = "*发送成功";
          }
              return true;
            
         } else {
           err_msg.innerHTML = "*手机格式输入不正确,发送失败";
        
             // document.getElementById('err_msg').innerHTML = "*";
             return false;
         }
     });
 });
 function djs(){
     send.value = times+"秒后重试";
     send.setAttribute('disabled','disabled');
     send.style.background='#ccc';
     send.style.border='1px solid #ccc';
     times--;
     if(times <= 0){
         send.value = "发送验证码";
         send.removeAttribute('disabled');
         times = 60;
         clearInterval(timer);
     }
 }

  function yzfn() {
    if(yz.value == "") {
        err_msg.innerHTML = "*验证码不能为空";
        return false;
    }else{
      return true;
    }
}
yz.onblur = yzfn;

 psd2.onfocus = function () {
    err_msg.innerHTML = "*由至少六位纯数字组成";
    }

   function pwfn() {
    if(psd2.value == "") {
        err_msg.innerHTML = "*密码不能为空";
        return false;
    }else{
        var regex3 = /^\d{6,}$/;
        if(regex3.test(psd2.value)){
            return true;
        }else{
            err_msg.innerHTML = "*密码格式不对";
            return false;
        }
    }
    }


 psd2.onblur = pwfn;

 function rpwfn() {
    if(qpsd2.value == "") {
        err_msg.innerHTML = "*确认密码不能为空";
        return false;
    }else{
      if(psd2.value == qpsd2.value) {
      return true;
     } else {
        err_msg.innerHTML = "*密码输入不一致";
        return false;
     }
    }
    
}
qpsd2.onblur = rpwfn;

function fn2() {
       var res3= telfn()
       var res4= yzfn()
         var res5= pwfn()
         var res6= rpwfn()
       return res3 &&  res4 && res5 && res6;
}


 $('#btn').on('click', function(){
     var res3= telfn()
     var res4= yzfn()
     var res5= pwfn()
     var res6= rpwfn()
     // console.log(res3)   
     //  console.log(res4)  
     //   console.log(res5)  
     //    console.log(res6)  
     if(   res3 && res4 && res5 && res6  ) {   
         $.ajax({
             type: 'POST',
             url: "/home/reg/create",
             data: $('form').serialize(),
             dataType: 'json',
             success: function (data) {
                 if (data.status == 2) {
                     window.location.href = "/home/success/index";
                 }
                 if (data.status == 1) {
                     document.getElementById('err_msg').innerHTML = "*该用户已存在";
                 }
                 if (data.status == 3 && res4 != '') {
                     document.getElementById('err_msg').innerHTML = "*手机验证码错误";
                 }
             }
         });
     }
 })






























